<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>  
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css"
	href="<c:url value="/static/jquery-easyui/themes/icon.css"/>">
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery-1.6.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/jquery.easyui.min.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.panel.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.datagrid.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/plugins/jquery.messager.js"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/ext-for-framework.js.jsp"/>"></script>
<script type="text/javascript"
	src="<c:url value="/static/jquery-easyui/locale/easyui-lang-zh_CN.js"/>"></script>
<script type="text/javascript"
			src="<c:url value="/static/js/common.js"/>"></script>
<script type="text/javascript">
    var editIndex = undefined;

	function initList(listDisplayEId) {
		$('#' + listDisplayEId).datagrid(
				{
					nowrap : false,
					striped : true,
					collapsible : true,
					remoteSort : true,
					notSelectByRow : false,
					/* frozenColumns : [ [ {
						field : 'ids',
						checkbox : true
					} ] ], */
					toolbar : [
							{
								
								id : listDisplayEId + '_btn_edit',
								text : '修改品级',
								iconCls : 'icon-edit',
								handler : function() {
								
									var row = $('#'+listDisplayEId).datagrid('getSelections');
										if(row.length == 0){
										$.messager.alert('提示','请选择一条记录操作！','info');
										return;
									}else{
										//var  jsonSun = "{ordId:'"+row[0]['ordId']+"',ordCustId:'"+row[0]['ordCustId']+"',ordSupId:'"+row[0]['ordSupId']+"'}";
										//var jsonFater = JSON.stringify(jsonSun);
										//改变编辑状态
										/* alert(0);
										for(var i=0; i<row.length; i++){
										    var rowIndex=$('#'+listDisplayEId).datagrid('getRowIndex',row[i]['ordMaterId']);
											$('#'+listDisplayEId).datagrid('endEdit', rowIndex);
										}
										alert(1); */
										var b = row[0]['ordMaterId']+"select";
										var select = document.getElementById(b);
										var str = "ordId="+row[0]['ordId']+"&ordMaterId="+row[0]['ordMaterId'] +"&ordMaterLevel="+select.value +"&ordSupId="+row[0]['ordSupId'];	
											$.messager.confirm('提示', '是否修改该条记录？', function(r){
											if (r){			
												$.ajax({type:'post',url:"<c:url value='/order/updateOrderLevel.do'/>"+"?"+str,dataType:"json",//设置查询参数及提交路径
					 							success:function(data){
													if(data.success){
														$.messager.alert("提示", "修改成功！", 'info');
														$('#'+listDisplayEId).datagrid('reload');
													}else{
														$.messager.alert("提示", data.msg, 'warning');
													}
												},
												error:function(){
												$.messager.alert("错误", "系统错误，请联系管理员！", 'error');
												}
												});
											} 
											$('#'+listDisplayEId).datagrid('reload');
											$('#'+listDisplayEId).datagrid('clearSelections');
											editIndex = undefined;
										});
									}
									$('#'+listDisplayEId).datagrid('clearSelections');
									editIndex = undefined;
								}
							} ],
					onLoadError : function() {
						$.messager.alert('错误', '获取数据失败，请与管理员联系！', 'error');
					} ,
					onClickRow : onClickRow 
				});

	};
	$(document).ready(function() {
		initList('listDisplay');
	});
	function formatRadio(value,rowData,rowIndex){
		return value="<input type='radio' class='myrad'  name='radioRole' />";
	}
	//角色状态展示0：有效；1为失效
	function formatDGStateField(value,row,index,field){
		if(!field){
			field = this.field;
		}
		var fields = field.split('.');
		var fieldValue = row;
		for(var i=0;i < fields.length;i++){
			if(fieldValue[fields[i]]==0){
			 fieldValue = "有效";
			}else if(fieldValue[fields[i]]==1){
				 fieldValue = "失效";
		    } 
		}
		return fieldValue;
	}
	function  goDetailedContent(val,row){
		return '<a href="#" onclick="constructionManager(\'' + row.id+ '\')">'+val+'</a>  '
	}
	
	function onClickRow(index){
		if (editIndex != index){
			if (endEditing()){
				$('#listDisplay').datagrid('selectRow', index)
						.datagrid('beginEdit', index);
				editIndex = index;
			} else {
				$('#listDisplay').datagrid('selectRow', editIndex);
			}
		}
	}
	function endEditing(){
		if (editIndex == undefined){return true}
		if ($('#listDisplay').datagrid('validateRow', editIndex)){
			var ed = $('#listDisplay').datagrid('getEditor', {index:editIndex,field:'ordMaterLevel'});
			var levelname = $(ed.target).combobox('getText');
			$('#listDisplay').datagrid('getRows')[editIndex]['levelname'] = levelname;
			$('#listDisplay').datagrid('endEdit', editIndex);
			editIndex = undefined;
			return true;
		} else {
			return false;
		}
	} 
	
    function golevel(value,row,index){
		//alert("<input class=\"easyui-combobox\" data-options=\"editor:{type:'combobox',options:{valueField: 'ordMaterLevel', textField: 'levelname', url:'<c:url value="/order/findMaterLevel.do"></c:url>',required:true}}\" />");
	    alert(index);
		alert(row['ordMaterId']);
		var url1 = 
		$.ajax({
            type: "POST",
            url: '<c:url value="/order/findMaterLevel.do"></c:url>'+'?',
            success: function(msg){
              alert( "Data Saved: " + msg );
              $('#dg').datagrid('loadData',msg);  //这里为什么没效果
            }
        }); 
		
		
		var finalstr = "<select class=\"easyui-combobox\" name='"+index+"select"+"' >"
	        +"</select>";
		return finalstr;
	} 
	function  goDetailedContent(val,rowData,rowIndex){
		return '<a href="#" onclick="constructionManager(\'' + rowData.ordSupId+'\',\''+ rowData.ordMaterId +'\')">'+val+'</a>  '
	}
	
	function constructionManager(supId,materId) {
		var new_win = window.open("<c:url value='/jsp/openIndexSun2.jsp?url=/order/lookupLevel.do'/>"+"?supId="+supId+"&materId="+materId,"sun2","width=400px,height=200px,status=no,scrollbars=yes");
		
		new_win.focus();
	}
</script>
</head>

<body>
    <form id="AddFoodForm" name="AddFoodForm" method="post">
		<table cellpadding="5">
			      <tr>
                    <td>
				        <input class="easyui-validatebox" type="hidden" name="ordId" required="true" validType="length[1,30]" value="${ordId }"/>
 			        </td>
                  </tr>
        </table>
    </form>

	<table id="listDisplay" title="供应商订单品级修改列表" singleSelect=true
		iconCls="icon-list" idField="ordMaterId"
		url="<c:url value="/order/findSupMaterDetailed.do?oid=${ordId }"/>"
		style="width: 800px; width: 1180px;" loadMsg="请稍候......"
		pagination="true" pageSize="10"
		pageList="[10,20,30,40,50,100,150,200]" sortName="roleId"
		rownumbers="true" sortOrder="asc">
		<thead>
				<tr>
				    <th field="id" width="25" align="center"  checkbox="true">
					</th> 
				    <th field="ordId" width="70"  sortable="true" >
						订单ID
					</th>	
 					<th field="ordCustId" width="70" sortable="true" >
						客户ID
					</th>
					<th field="ordCustName" width="70" sortable="true" >
						客户名
					</th>
					<th field="ordSupId" width="70" sortable="true" >
						供货商ID
					</th>	
					<th field="ordSupName" width="80" sortable="true" >
						供货商名
					</th>	
					<th field="ordMaterId" width="70" sortable="true" >
						材料id
					</th>
					<th field="ordMaterName" width="100"  sortable="true" >
						材料名
					</th>
					<th field="ordMaterWeight" width="100"  sortable="true" >
						材料重量（公斤）
					</th>	
					<!--
					<th data-options="field:'ordMaterLevel',width:50,
    						formatter:function(value,row){
    							return row.levelname;
    						},
    						editor:{
    							type:'combobox',
    							options:{
    								valueField:'ordMaterLevel',
    								textField:'levelname',
    								method:'get',
    								url:'<c:url value="/order/findMaterLevel.do"> <c:param name="oid" value="1"></c:param>      </c:url>',
    								required:true
    							}
    						}">品级
    				</th>
    				 -->
    				<th field="ordMaterLevelSelect"   width="80"  sortable="true" >
						品级
    				</th>
    				 <!--  
    				<th field="content" formatter="goDetailedContent"  width="80"  sortable="true" >
						可选品级
					</th>
					-->
					
    				<th field="ordMaterWeightReal" width="120"  sortable="true" >
						实际材料重量(公斤)
					</th>	
 				</tr>
		</thead>
	</table>
</body>
</html>